package com.promis.party.ui.home.homebanner.mylearn;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.widget.paging.PageRefreshRecyclerView;
import com.promis.widget.recycler.LinearSpacingItemDecoration;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

/**
 * Created by jidanbo on 2018/2/2.
 */

public class ExamTotalFragment extends Fragment {

    private ContextHelper contextHelper;

    private LinearLayout rootLayout;
    private ExamTotalListAdapter adapter;
    private PageRefreshRecyclerView recyclerView;

    public final static ExamTotalFragment newInstance() {
        ExamTotalFragment fragment = new ExamTotalFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootLayout = (LinearLayout) inflater.inflate(R.layout.fragment_exam_total, null, false);
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        recyclerView = rootLayout.findViewById(R.id.fragment_exam_total_rcyv);

        initData();
        initListener();
        return rootLayout;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    private void initData() {
        contextHelper = new ContextHelper(getContext());

        RecyclerView recycler = recyclerView.getRecyclerView();
        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getContext(), recycler);
        recycler.addItemDecoration(new LinearSpacingItemDecoration(getContext(), LinearLayoutManager.VERTICAL, 0, R.color.split_line));
        adapter = new ExamTotalListAdapter(getContext());
        recycler.setAdapter(adapter);
    }

    private void initListener() {
        adapter.setOnItemClickListener(new ExamTotalListAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
//                Intent intent = new Intent(getContext(), MyQuestionsDetailActivity.class);
//                startActivity(intent);
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
            }
        }
    }

}
